/*
 * @Author: your name
 * @Date: 2021-11-01 19:22:18
 * @LastEditTime: 2021-11-02 20:46:51
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \练习\snake\src\utils\ticker.ts
 */
let startTime = Date.now()
type Ticker = Function;
let tickers: Array<Ticker> = []

const handleFrame = () => {
	tickers.forEach((ticker) => {
		ticker(Date.now() - startTime)
	})
	startTime = Date.now()
	requestAnimationFrame(handleFrame)
}
requestAnimationFrame(handleFrame)

export function addTicker(ticker: Ticker) {
	tickers.push(ticker)
}

export function stopTicker() {
	tickers = []
}
